package org.mech.sefer.client.ui.component.bibletreeview;

import java.util.List;

import javax.annotation.Resource;

import org.apache.pivot.util.ListenerList;
import org.apache.pivot.wtk.ButtonStateListener;
import org.mech.sefer.client.mvp.spring.AbstractSpringPresenter;
import org.mech.sefer.client.mvp.wtk.ComponentView;
import org.mech.sefer.client.ui.component.bibletreeview.BibleTreePresenter.View;
import org.mech.sefer.client.ui.event.BibleEvents.BibleAvailableEvent;
import org.mech.sefer.client.ui.event.BibleEvents.BibleAvailableHandler;
import org.mech.sefer.model.bible.TBible;
import org.mech.sefer.shared.common.CollectionUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Scope("prototype")
@Component("bibleTreePresenter")
public class BibleTreePresenter extends AbstractSpringPresenter<View> implements BibleAvailableHandler {
	
	
	public interface View extends ComponentView {
		void setData(List<TBible> bibles);
		ListenerList<ButtonStateListener> getNormalButton();
	}
	
	@Override
	protected void onBind() {
		registerHandler(BibleAvailableEvent.class, this);
	
	}

	@Override
	public void onBibleAvailableEvent(BibleAvailableEvent event) {
		if(CollectionUtils.isNotEmpty(event.getData())){
			getView().setData(event.getData());
		}
	}
	
	@Resource(name="bibleTreeView")
	@Override
	public void setView(View view) {
		super.setView(view);
	}

}
